﻿using System;
using FiveMonth.FormWork.Word;
using NUnit.Framework;

namespace Tester
{
    public class TestWordTemplateDocX
    {
        [Test]
        public void Test2()
        {
            var data = Mock.GetScore();
            var data2 = Mock.GetScore2();

            var mappers = new BookmarkInfos<ScoreList>();

            mappers.Add("title", (d, a) => d.Title);
            mappers.Add("author", (d, a) => d.Author);
            mappers.Add("createdate", (d, a) => d.CreateDate.ToString("yyyy年MM月dd日"));
            mappers.AddImage("sign", (d, a) => d.Sign, 100, 100);
            mappers.Add("loop_id", (d, a) => d.Students[a[0]].Id);
            mappers.Add("loop_name", (d, a) => d.Students[a[0]].Name);
            mappers.Add("loop_age", (d, a) => d.Students[a[0]].Age.ToString());
            mappers.Add("loop_sex", (d, a) => d.Students[a[0]].Sex);
            mappers.Add("loop_totalscore", (d, a) => d.Students[a[0]].TotalScore.ToString());
            mappers.Add("loop_avg", (d, a) => d.Students[a[0]].AvgScore.ToString("N1"));
            mappers.Add("loop_item_subject", (d, a) => d.Students[a[0]].Subjects[a[1]].Subject);
            mappers.Add("loop_item_score", (d, a) => d.Students[a[0]].Subjects[a[1]].Score.ToString());
            mappers.AddLoop("loop_", (d, a) => d.Students.Count);
            mappers.AddLoop("loop_item_", (d, a) => d.Students[a[0]].Subjects.Count);

            var result = Template.ApplyData("D:\\Documents\\Template.DocX\\分行成绩表模板.docx", "D:\\Documents\\Template.DocX\\分行成绩表.doc", data, mappers);
            Console.WriteLine(result);
            var result2 = Template.ApplyData("D:\\Documents\\Template.DocX\\分行成绩表模板.docx", "D:\\Documents\\Template.DocX\\分行成绩表2.doc", data2,
                mappers);
            Console.WriteLine(result2);
        }
    }
}